using System.Collections;
using System.Collections.Generic;

namespace VirtualDeveloper.Filters
{
    internal class SkipperEnumerator<T> : IEnumerator<T>
    {
        private readonly IEnumerator<T> enumerator;
        private readonly int everyLineCount;

        public SkipperEnumerator(IEnumerable<T> enumerable, int everyLineCount)
        {
            enumerator = enumerable.GetEnumerator();
            this.everyLineCount = everyLineCount;
        }

        public void Dispose()
        {
            enumerator.Dispose();
        }

        public bool MoveNext()
        {
            var hasNext = false;
            for (var i = 0; i < everyLineCount; i++)
            {
                hasNext = enumerator.MoveNext();

                if (!hasNext) return false;
            }

            return hasNext;
        }

        public void Reset()
        {
            enumerator.Reset();
        }

        public T Current { get { return enumerator.Current; } }

        object IEnumerator.Current
        {
            get { return Current; }
        }
    }
}